package com.berchen.test;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ConcurrentHashMap 线程安全的Map 底层就是16个HashTable
 */
public class ConcurrentHashMapDemo {
    public static void main(String[] args) {

        Map map=new ConcurrentHashMap();

        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                map.put(UUID.randomUUID().toString().substring(5),UUID.randomUUID().toString());
            }).start();
        }
        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(map);
        
        Map map1=new HashMap();
        for (int i = 0; i < 150; i++) {
            new Thread(()->{
                map1.put(UUID.randomUUID().toString().substring(5),UUID.randomUUID().toString());
            }).start();
        }

        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(map1);
    }
}
